package com.scau402.system1.repository.impl;

import com.scau402.system1.mapper.WmsWarehouseStorageMapper;
import com.scau402.system1.repository.IWmsStorageRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * 仓位Repository实现类
 * @since 2024/2/3
 */
@Repository
@Slf4j
public class WmsStorageRepositoryImpl implements IWmsStorageRepository {
    @Autowired
    private WmsWarehouseStorageMapper storageMapper;

    /**
     * 根据仓位id获取子仓位们的id
     * @param id 仓位id
     * @return 子仓位id列表
     */
    @Override
    public List<Long> findChildStorageIdById(Long id) {
        return Optional.ofNullable(storageMapper.selectChildStorageIdById(id)).orElse(new ArrayList<>());
    }

    /**
     * 根据仓位id获取已使用的容量
     * @param storageId 仓位id
     * @return 容量大小
     */
    @Override
    public Long findUsedCapById(Long storageId) {
        return Optional.ofNullable(storageMapper.selectUCById(storageId)).orElse(-1L);
    }

    /**
     * 根据仓位id获取仓位名称
     * @param storageId 仓位id
     * @return 仓位名称
     */
    @Override
    public String findNameById(Long storageId) {
        if(storageId<0) return null;
        return storageMapper.selectNameById(storageId);
    }
}
